package com.breezelin.freshmarket.entities.req;

/**
 * Created by Breeze Lin
 * 2016/9/23 14:09
 * breezesummerlin@163.com
 */

import com.breezelin.freshmarket.entities.JsonStruct;
import com.breezelin.freshmarket.utils.SignUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 注册请求体
 */
public class RegisterReq implements JsonStruct {

	/*
	"Body": {
        "Password2": "E4+bYSFUcYt4dKgfbpHzMg==",
        "ActivityCode": "",
        "UserName": "egsmPxTmb2y+wej0eOiStw==",
        "Password": "E4+bYSFUcYt4dKgfbpHzMg==",
        "Code": "wE2/p0qCSUbZkhF59jVm1w==",
        "Mobile": "egsmPxTmb2y+wej0eOiStw=="
    }
	 */

	/**
	 * 用户名
	 */
	private String userName;
	/**
	 * 密码
	 */
	private String password;
	/**
	 * 确认密码
	 */
	private String password2;
	/**
	 * 邀请码
	 */
	private String activityCode;
	/**
	 * 验证码
	 */
	private String code;
	/**
	 * 手机号码
	 */
	private String mobile;

	public RegisterReq(String userName, String mobile, String password, String code) {
		this.userName = userName;
		this.password = password;
		// 不再进行密码确认
		this.password2 = password;
		// 邀请码，忽略
		this.activityCode = "";
		this.code = code;
		this.mobile = mobile;
	}

	@Override
	public void fromJson(JSONObject jsonObject) {
	}

	@Override
	public JSONObject toJson() {
		JSONObject ret = new JSONObject();
		try {
			// 所有数据在形成json数据的时候，会进行加密
			ret.put("UserName", SignUtil.encrypt(userName));
			ret.put("Password", SignUtil.encrypt(password));
			ret.put("Password2", SignUtil.encrypt(password2));
			ret.put("ActivityCode", SignUtil.encrypt(activityCode));
			ret.put("Code", SignUtil.encrypt(code));
			ret.put("Mobile", SignUtil.encrypt(mobile));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return ret;
	}
}
